<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="xdr-exceptions.html" />
<link rel="prev" href="xdr-packer-objects.html" />
<link rel="parent" href="module-xdrlib.html" />
<link rel="next" href="xdr-exceptions.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>9.5.2 Unpacker Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="9.5.1 packer Objects"
  href="xdr-packer-objects.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="9.5 xdrlib  "
  href="module-xdrlib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="9.5.3 Exceptions"
  href="xdr-exceptions.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="xdr-packer-objects.html">9.5.1 Packer Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-xdrlib.html">9.5 xdrlib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="xdr-exceptions.html">9.5.3 Exceptions</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION0011520000000000000000"></a><a name="xdr-unpacker-objects"></a>
<br>
9.5.2 Unpacker Objects 
</h2>

<p>
The <tt class="class">Unpacker</tt> class offers the following methods:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2111' xml:id='l2h-2111' class="method">reset</tt></b>(</nobr></td>
  <td><var>data</var>)</td></tr></table></dt>
<dd>
Resets the string buffer with the given <var>data</var>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2112' xml:id='l2h-2112' class="method">get_position</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Returns the current unpack position in the data buffer.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2113' xml:id='l2h-2113' class="method">set_position</tt></b>(</nobr></td>
  <td><var>position</var>)</td></tr></table></dt>
<dd>
Sets the data buffer unpack position to <var>position</var>.  You should be
careful about using <tt class="method">get_position()</tt> and <tt class="method">set_position()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2114' xml:id='l2h-2114' class="method">get_buffer</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Returns the current unpack data buffer as a string.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2115' xml:id='l2h-2115' class="method">done</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Indicates unpack completion.  Raises an <tt class="exception">Error</tt> exception
if all of the data has not been unpacked.
</dl>

<p>
In addition, every data type that can be packed with a <tt class="class">Packer</tt>,
can be unpacked with an <tt class="class">Unpacker</tt>.  Unpacking methods are of the
form <code>unpack_<var>type</var>()</code>, and take no arguments.  They return the
unpacked object.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2116' xml:id='l2h-2116' class="method">unpack_float</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Unpacks a single-precision floating point number.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2117' xml:id='l2h-2117' class="method">unpack_double</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Unpacks a double-precision floating point number, similarly to
<tt class="method">unpack_float()</tt>.
</dl>

<p>
In addition, the following methods unpack strings, bytes, and opaque
data:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2118' xml:id='l2h-2118' class="method">unpack_fstring</tt></b>(</nobr></td>
  <td><var>n</var>)</td></tr></table></dt>
<dd>
Unpacks and returns a fixed length string.  <var>n</var> is the number of
characters expected.  Padding with null bytes to guaranteed 4 byte
alignment is assumed.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2119' xml:id='l2h-2119' class="method">unpack_fopaque</tt></b>(</nobr></td>
  <td><var>n</var>)</td></tr></table></dt>
<dd>
Unpacks and returns a fixed length opaque data stream, similarly to
<tt class="method">unpack_fstring()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2120' xml:id='l2h-2120' class="method">unpack_string</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Unpacks and returns a variable length string.  The length of the
string is first unpacked as an unsigned integer, then the string data
is unpacked with <tt class="method">unpack_fstring()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2121' xml:id='l2h-2121' class="method">unpack_opaque</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Unpacks and returns a variable length opaque data string, similarly to
<tt class="method">unpack_string()</tt>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2122' xml:id='l2h-2122' class="method">unpack_bytes</tt></b>(</nobr></td>
  <td><var></var>)</td></tr></table></dt>
<dd>
Unpacks and returns a variable length byte stream, similarly to
<tt class="method">unpack_string()</tt>.
</dl>

<p>
The following methods support unpacking arrays and lists:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2123' xml:id='l2h-2123' class="method">unpack_list</tt></b>(</nobr></td>
  <td><var>unpack_item</var>)</td></tr></table></dt>
<dd>
Unpacks and returns a list of homogeneous items.  The list is unpacked
one element at a time
by first unpacking an unsigned integer flag.  If the flag is <code>1</code>,
then the item is unpacked and appended to the list.  A flag of
<code>0</code> indicates the end of the list.  <var>unpack_item</var> is the
function that is called to unpack the items.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2124' xml:id='l2h-2124' class="method">unpack_farray</tt></b>(</nobr></td>
  <td><var>n, unpack_item</var>)</td></tr></table></dt>
<dd>
Unpacks and returns (as a list) a fixed length array of homogeneous
items.  <var>n</var> is number of list elements to expect in the buffer.
As above, <var>unpack_item</var> is the function used to unpack each element.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-2125' xml:id='l2h-2125' class="method">unpack_array</tt></b>(</nobr></td>
  <td><var>unpack_item</var>)</td></tr></table></dt>
<dd>
Unpacks and returns a variable length <var>list</var> of homogeneous items.
First, the length of the list is unpacked as an unsigned integer, then
each element is unpacked as in <tt class="method">unpack_farray()</tt> above.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="9.5.1 packer Objects"
  href="xdr-packer-objects.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="9.5 xdrlib  "
  href="module-xdrlib.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="9.5.3 Exceptions"
  href="xdr-exceptions.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="xdr-packer-objects.html">9.5.1 Packer Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-xdrlib.html">9.5 xdrlib  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="xdr-exceptions.html">9.5.3 Exceptions</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
